package zisu.netty.practice.RPC.demo.invoke;

import zisu.netty.practice.RPC.client.RpcClient;
import zisu.netty.practice.RPC.client.RpcFuture;
import zisu.netty.practice.RPC.client.proxy.RpcAsyncProxy;
import zisu.netty.practice.RPC.demo.User;
import java.util.concurrent.ExecutionException;

public class ConsumerStarter {

	//同步的方式
	public static void sync() {
		//	rpcClient
		RpcClient rpcClient = new RpcClient();
		rpcClient.initClient("127.0.0.1:8765", 3000);
		//利用 反射 直接 获取 Service对象，然后直接调用就可以了。

		HelloService helloService = (HelloService) rpcClient.invokeSync(HelloService.class);
		String result = helloService.hello("zhang3");
		System.err.println("结果: "+result);
	}

	//异步的方式
	public static void async() throws InterruptedException, ExecutionException {
		RpcClient rpcClient = new RpcClient();
		rpcClient.initClient("127.0.0.1:8765", 3000);
		RpcAsyncProxy proxy = rpcClient.invokeAsync(HelloServiceImpl.class);
		RpcFuture future = proxy.call("hello", "li4");
		User user = new User("001", "wang5", "11", "desc1");
		RpcFuture future2 = proxy.call("hello", user);

		Object result = future.get();
		Object result2 = future2.get();
		System.err.println("result: " + result);
		System.err.println("result2: " + result2);
	}
	
	public static void main(String[] args) throws Exception {
		//async();
		sync();
		//syncMy();
	}
}
